import Vue from 'vue'
import VueRouter from 'vue-router'
//组件引入
import Shouye from '../views/shouye.vue'
import Houtaihome from '../views/houtai/home.vue'
import Jibenxinxi from '../views/houtai/yonghu/jibenxinxi.vue'
import Shenhe from '../views/houtai/yonghu/shenhe.vue'
import Shezhibiao from '../views/houtai/jiankang/shezhibiao.vue'
import Wenzhang from '../views/houtai/wenzhang/wenzhang.vue'
import Luntan from '../views/houtai/luntan/tiezi/luntan.vue'
import Youhujiankang from '../views/houtai/jiankang/yonhujiankang.vue'
import Classification from '../views/houtai/luntan/tiezifenlei/tiezifenlei.vue'
import Tiezixiangqing from '../views/qiantai/luntang/tiezixiangqing.vue'
import XuetangHou from '../views/houtai/xuetang/xuetang.vue'
import YinshiHou from '../views/houtai/yinshi/yinshi.vue'

// 以下是前台组件
import Qiantaihome from '../views/qiantai/qiantaihome.vue'
import Shouyezhangshi from '../views/qiantai/shouyezhangshi.vue'
import Jieshao from '../views/qiantai/jieshao.vue'
import Qianuntang from '../views/qiantai/luntang/luntang.vue'
import Sousuo from '../views/qiantai/search/sousuo.vue'
import Qianwenzhang from '../views/qiantai/wenzhang/wenzhang.vue'
import Wodetiezi from '../views/qiantai/my/wodetiezi.vue'
import Wodewenzhang from '../views/qiantai/my/wodewenzhang.vue'
import Wodeshoucang from '../views/qiantai/my/wodeshoucang.vue'
import Wodeziliao from '../views/qiantai/sys/wodeziliao.vue'
import Xiaoxi from '../views/qiantai/sys/xiaoxi.vue'
import Xiugaimima from '../views/qiantai/sys/xiugaiima.vue'
import Wenzhangxiangqing from '../views/qiantai/wenzhang/wenzhangxiangqing.vue'
import Yinshi from '../views/qiantai/food/yinshi.vue'
import Xuetang from '../views/qiantai/my/xuetang.vue'

import Yonghuxinxichaxun from '../views/qiantai/yonghuxinxichaxun/yonghuxinxichaxun'
import Putonzhuce from '../views/putonzhuce.vue'
import Tanzhuce from '../views/tanzhuce.vue'
import Yishengzhuce from '../views/yishengzhuce.vue'


Vue.use(VueRouter)


const router =new VueRouter(
    {
        routes :[
            {path:'/',redirect:'/qiantaihome/shouyezhangshi'},
            {path:'/shouye', component:Shouye,name: 'shouye',redirect:'/shouye/putonzhuce',
                children: [{path:'putonzhuce',component:Putonzhuce },
                    {path:'tanzhuce',component:Tanzhuce },
                    {path:'yishengzhuce',component:Yishengzhuce }
                    ]},
            //
            {path:'/qiantaihome', component:Qiantaihome,redirect:'/qiantaihome/shouyezhangshi',name:'qiantaihome',
                       //
                children:[{path:'shouyezhangshi',component: Shouyezhangshi},
                    {path:'jieshao',component: Jieshao,name:'jieshao'},
                    {path:'luntang',component: Qianuntang,name:'luntang'},
                    {path:'sousuo',name:'sousuo',component: Sousuo,},
                    {path:'qianwenzhang',component: Qianwenzhang,name:'qianwenzhang'},
                    {path:'wodetiezi',component: Wodetiezi,name:'wodetiezi'},
                    {path:'wodewenzhang',component: Wodewenzhang,name:'wodewenzhang'},
                    {path:'wodeshoucang',component: Wodeshoucang,name:'wodeshoucang'},
                    {path:'wodeziliao',component: Wodeziliao,name:'wodeziliao'},
                    {path:'xiaoxi',component: Xiaoxi,name:'xiaoxi'},
                    {path:'xiugaiima',component: Xiugaimima,name:'xiugaiima'},
                    {path:'tiezixiangqing',component: Tiezixiangqing,name:'tiezixiangqing'},
                    {path:'wenzhangxiangqing',component: Wenzhangxiangqing,name:'wenzhangxiangqing'},
                    {path:'yinshi',component: Yinshi,name:'yinshi'},
                    {path:'xuetang',component: Xuetang,name:'xuetang'},
                    {path:'yonghuxinxichaxun',component: Yonghuxinxichaxun,name:'yonghuxinxichaxun'}
                ]},
            {path:'/houtaihome',redirect:'/houtaihome/jibenxinxi',
                component:Houtaihome,name:'houtaihome',
                children:[
                    {path:'jibenxinxi',component:Jibenxinxi},
                    {path:'shenhe',component:Shenhe},
                    {path:'shezhibiao',component:Shezhibiao},
                    {path:'wenzhang',component:Wenzhang},
                    {path:'luntan',component:Luntan},

                    {path:'tiezifenlei',component:Classification},

                    {path:'yonhujiankang',component:Youhujiankang},
                    {path:'xuetangHou',component:XuetangHou},
                    {path:'yinshiHou',component:YinshiHou}
                ]
            }
        ]
    }
)
//把VueRouter原型对象的push方法保存一份
let originPush = VueRouter.prototype.push;
//把VueRouter原型对象的replace方法保存一份
let originReplace = VueRouter.prototype.replace;

//重写push
//location:告诉原来push方法，你往哪里跳转（传递哪些参数)
//resolve:成功的回调
//reject:失败时的回调
VueRouter.prototype.push = function (location, resolve, reject) {
    if (resolve && reject) {
        originPush.call(this, location, resolve, reject);
    } else {
        originPush.call(
            this,
            location,
            () => {},
            () => {}
        );
    }
};

//重写replace
VueRouter.prototype.replacce = function (location, resolve, reject) {
    if (resolve && reject) {
        originReplace.call(this, location, resolve, reject);
    } else {
        originReplace.call(
            this,
            location,
            () => {},
            () => {}
        );
    }
};

// router.beforeEach((to, from, next)=>{
//     if(to.path ==='/login') return next()
//     const tokenStr =window.sessionStorage.getItem('token')
//     if(!tokenStr) return next('/login')
//     next()
// })
//

export default router
